/*
 * Monoid.cpp
 *
 *  Created on: May 13, 2012
 *      Author: kobe
 */

#include "Monoid.h"

Monoid::Monoid(std::string input)
: Proposition (MONOID){
	//std::cout << "Monoid input:" << input << std::endl;
	std::string content(input, 2, input.size() - 2);
	size_t left, right;
	std::string sleft = getBracketContent(content, &left, &right);
	std::string ncontent(content, right + 2, content.size() - right - 2);
	std::string sright = getBracketContent(ncontent, &left, &right);
	mLeft = createProposition(sleft);
	mRight = createProposition(sright);
}

Monoid::Monoid(Proposition* left, Proposition* right) :
		Proposition(MONOID) {
	mRight = right;
	mLeft = left;
}

Monoid::~Monoid() {
	// TODO Auto-generated destructor stub
}

std::string Monoid::toString() {
	std::string result;
	result += "md{";
	result += mLeft->toString();
	result += "}{";
	result += mRight->toString();
	result += '}';
	return result;
}

Proposition *Monoid::getLeft() const {
	return mLeft;
}

Proposition *Monoid::getRight() const {
	return mRight;
}

bool Monoid::compare(Proposition* p) {
	if (p->getPropName() != MONOID) {
		return false;
	} else {
		Monoid *md = (Monoid*) p;
		return mLeft->compare(md->getLeft()) && mRight->compare(md->getRight());
	}
}

std::string Monoid::toLatex() {
	std::string s;
	if (mLeft->getPropName() != ACTION && mLeft->getPropName() != MONOID) {
		s += "(";
	}
	s += mLeft->toLatex();
	if (mLeft->getPropName() != ACTION && mLeft ->getPropName() != MONOID) {
		s += ")";
	}

	s += " \\bullet ";

	if (mRight->getPropName() != ACTION && mRight->getPropName() != MONOID) {
		s += "(";
	}
	s += mRight->toLatex();
	if (mRight->getPropName() != ACTION && mRight->getPropName() != MONOID) {
		s += ")";
	}

	return s;
}

bool Monoid::isAction()	 {
	return true;
}

